#include "OclLapack.h"
#include "clAmdBlas.h"
#include "../clUtils.h"
#include "../ClMem.h"
#include <cmath>

using namespace std;

void OclLapack::sger(int m, int n, float alpha, 
		const cl_ptr x, int incX,
		const cl_ptr y, int incY,
		cl_ptr a, int lda)
{
	Measure measure("sger-ocl");
	
	cl_event event;
	CL_CHECK(clAmdBlasSger(clAmdBlasColumnMajor, m, n, alpha,
			x.handle, x.offset, incX,
			y.handle, y.offset, incY,
			a.handle, a.offset, lda,
			1, &queue, 0, NULL, &event));
	
	ClEvent(event).wait();
}

int OclLapack::sger(int *m, int *n, float *alpha, float *x, 
		int *incx, float *y, int *incy, float *a, int *lda) 
{
	size_t sizeA = (*lda) * (*n);	
    	
	ClMem<float> memA(queue, sizeA, a);
	ClMem<float> memX(queue, 1 + (*m - 1) * abs(*incx), x);
	ClMem<float> memY(queue, 1 + (*n - 1) * abs(*incy), y);

	sger(*m, *n, *alpha,		
        cl_ptr(memX), *incx,
        cl_ptr(memY), *incy,
		cl_ptr(memA), *lda);

	memA.beginRead(a, 0, sizeA).wait();
    
    return 0;
}
